
<%
'''jianbook 函数定义
''' ==================================================================
''' 版权所有 http://www.9416.cn
''' ------------------------------------------------------------------
''' 此程序为免费开源版，个人可免费自由使用，不得作为商业用途，不可以修改再次发布！
''' ------------------------------------------------------------------
''' 个人使用需要保留版权，如需去除版权请联系作者购买。
''' ==================================================================


set jianbook=new jianbook_function

Class AutoCloseConnection
    Private Sub Class_Terminate
        If isobject(conn) or conn.state=1  Then 
		conn.Close
		Set conn=Nothing
		
		end if
    End Sub
End Class

Set autoCloseConn = New AutoCloseConnection	

class jianbook_function

Function RndNumber(MaxNum,MinNum)
Randomize 
RndNumber=int((MaxNum-MinNum+1)*rnd+MinNum)
RndNumber=RndNumber
End Function

function isadmin()

if sysinfo("token")=request.Cookies("admin")("token") then
isadmin=true
else
isadmin=false
end if

end function

public function sysinfo(t1)
set frs=server.CreateObject("adodb.recordset")
frs.open "select * from info ",conn,1,1
if not frs.eof then
sysinfo=trim(frs(t1))
end if
frs.close

End Function





public function verification()
dim sitekey
verification=false
if sysinfo("key")<>"" then
sitekey=decryptstr(sysinfo("key"))

if isNumeric(sitekey) and len(sitekey)=6 then
verification=true
else
verification=false
end if
end if
End Function


public sub user_tx(id,ip)
select case id
case "-1"
author_tx="<img src='ui/images/user_08.png' width='149' height='150' />"
author_type="游客"

case "0"
author_name="admin"
author_tx="<a href='"&webroot&"index.asp?uid=0'><img src='ui/images/user_01.jpg' /></a>"
author_type="管理员"
author_jf=999999
set rs2=conn.execute("select count(*)as nums from comment where uid='0' ")
author_num=rs2("nums")
rs2.close
case else
sql="select * from [user] where id="&id
set rs2=conn.execute(sql)

if not rs2.eof then
author_name=rs2("username")

end if

rs2.close
set rs2=conn.execute("select count(*)as nums from comment where uid='"&id&"' ")
author_num=rs2("nums")
rs2.close
set rs2=conn.execute("select sum(point)as nums from user_point where uid="&id)
if isnull(rs2("nums")) then
author_jf=0
else
author_jf=rs2("nums")
end if
rs2.close
sql="select * from [user] where id="&id
rs2.open sql,conn,1,1
if not rs2.eof then
if isnull(rs2("pic")) then
author_tx="<a href='"&webroot&"index.asp?uid="&id&"'><img src='ui/images/user_03.jpg' /></a>"
else
author_tx="<a href='"&webroot&"index.asp?uid="&id&"'><img src='"&rs2("pic")&"' /></a>"
end if
else
author_tx="<a href='"&webroot&"index.asp?uid="&rs("uid")&"'><img src='ui/images/user_03.jpg' /></a>"
end if
rs2.close
author_type="会员"
end select


htmls=htmls&"<div class=c_tx>"&author_tx&"</div>"
if id>=0 then

htmls=htmls&"<div class=""author-info-card"" >"
htmls=htmls&"<div class=""avatar-container-80 center""> <div  class=""author-avatar"" >"&author_tx&"</div></div>"
htmls=htmls&"  <div class=""presonal-info""><span class=author-nam >"&author_name&"</span></div>"
htmls=htmls&" <div class=""position-info""><span >"&look_ip(ip)&"&nbsp;|&nbsp;"&author_type&"</span></div>"
htmls=htmls&" <div class=info-num> <div class=work><p>发布</p><p class=num >"&author_num&"</p></div>"
htmls=htmls&" <div class=fans><p>积分</p><p class=num >"&author_jf&"</p></div></div>"
htmls=htmls&" <div class=btn-area >"

htmls=htmls&"<input type=""button"" title=""发私信"" class=""btn-default-secondary"" value=""私信"" onclick=""tc('私信【"&author_name&"】','lib/message.asp?class=2&send="&id&"',800,400)"">"
htmls=htmls&" </div></div>"
end if

 response.Write htmls
End sub



public function css()

if (verification()) then 
css=sysinfo("skin") 
else 
css="default" 
end if
End Function

public function cor()

if (verification()) then 
cor=sysinfo("cor") 

else 
cor="Powered by <a href=""//book.9416.cn"" target=""_blank"">Jianbook</a>"&jianbook_version&"" 

end if

End Function




public function skin()
if (verification()) then 
set frs=server.CreateObject("adodb.recordset")
frs.open "select * from info ",conn,1,1
if not frs.eof then
if frs("skin")="diy" then
if trim(frs("bgimg"))<>"" then
skin="<style>body{background-image: url("&webroot&frs("bgimg")&");}</style>"
else
skin="<style>body{"&frs("bgcss")&"}</style>"

end if
end if
end if
frs.close
else
skin=""
end if

End Function


public function wskin()
if (verification()) then 
set frs=server.CreateObject("adodb.recordset")
frs.open "select * from info ",conn,1,1
if not frs.eof then
if frs("skin")="diy" then

wskin="<style>body{"&frs("bgcss")&"}</style>"


end if
end if
frs.close
else
wskin=""
end if

End Function



public function utype(id)
select case id
case 0
utype="游客"
case 1
utype="管理员"

case 2
utype=" 会员"
end select
End Function



public function point(t1)
set frs=server.CreateObject("adodb.recordset")
frs.open "select * from user_set",conn,1,1
if not frs.eof then
points=split(frs("point"),",")
end if
frs.close
point=points(t1)
End Function



public function myip()
myip= Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If myip = "" Then
myip= Request.ServerVariables("REMOTE_ADDR")
End If

 end function


public function jcount(t1)


set frs=server.CreateObject("adodb.recordset")
 sql="select * from [count] where ip='"&jianbook.myip()&"' and datediff('d',intime,now())=0 "

 frs.open sql,conn,3,3
if not frs.eof then
frs("pv")=frs("pv")+1
frs.update
else
 frs.addnew
 frs("useragent")=Request.ServerVariables("http_user_agent")
 if Request.ServerVariables("HTTP_REFERER")="" then
 frs("url")="直接访问"
 else
  frs("url")=Request.ServerVariables("HTTP_REFERER")
 end if
	frs("addr")=look_ip(jianbook.myip())
     frs("pv")=1
	
	 frs("ip")=jianbook.myip()
	
   frs.update
  
   end if
 frs.close
 select case t1
 case 1
 response.Write "<script>homeauzs()</script>"
  case 2
 response.Write "<script>formauzs()</script>"
 end select
end function


  
public function  demomsg()
  if request.Cookies("admin")("user")="demo" then
response.Write("<script>layui.use('layer', function(){var  layer = layui.layer")
Response.Write(vbCr)
Response.Write("layer.msg('&#32593;&#31449;&#20165;&#20316;&#20026;&#28436;&#31034;');")
Response.Write(vbCr)
response.Write("})</script>")
response.End()
end if
end function

public function  demojson()
if request.Cookies("admin")("user")="demo" then
response.write "{""info"": ""&#31243;&#24207;&#20165;&#20316;&#20026;&#28436;&#31034;"",""status"": ""n""}"
response.End()

elseif not jianbook.isadmin() and request.cookies("user")("login")<>"true"  then
response.write "{""info"": ""您没有权限"",""status"": ""n""}"
response.End()
end if

end function


public function  mesjson()
if request.Cookies("admin")("user")="demo" then
response.write "{""info"": ""&#31243;&#24207;&#20165;&#20316;&#20026;&#28436;&#31034;&#44;&#22914;&#26524;&#35201;&#21457;&#24067;&#35780;&#35770;&#35831;&#36864;&#20986;&#31649;&#29702;"",""status"": ""n""}"
response.End()
end if

'if request("author")<>jianbook.un_asc("&#98;&#111;&#111;&#107;&#46;&#57;&#52;&#49;&#54;&#46;&#99;&#110;") then
'response.write "{""info"": ""&#19981;&#35201;&#20462;&#25913;&#25110;&#21024;&#38500;&#29256;&#26435;&#20449;&#24687;"",""status"": ""n""}"
'response.end()
'end if

end function


public function  mgbox(str,str1)

response.Write("<script>layui.use('layer', function(){var  layer = layui.layer")
Response.Write(vbCr)
Response.Write("layer.msg('"&str&"');")
Response.Write(vbCr)
response.Write("setTimeout(""window.location.href='"&str1&"';"",1000); })</script>")
end function

public function qxmsg()

if sysinfo("token")<>request.Cookies("admin")("token") then
response.Write("没有权限")
response.end
else



end if
end function

public function uqxmsg()
if request.Cookies("user")("login")="" then
response.Write("没有权限")

response.end
end if
end function



public function sendmail(byval t1,byval t2)
if jianbook.sysinfo("ismail")="0" then exit function
		err.clear
		sendmail=false
	on error resume next
		dim objmail,objconfig
				set objmail=server.createobject("cdo.message") 
				set objconfig=server.createobject("cdo.configuration") 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")="true" 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")=jianbook.sysinfo("smtp")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendusername")=jianbook.sysinfo("mailuser")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")=jianbook.sysinfo("mailpass")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/languagecode")="0x0804" 
				objconfig.fields.update() 
				set objmail.configuration=objconfig
				objmail.subject=t1
				objmail.from=jianbook.sysinfo("mailuser")
				objmail.to=jianbook.sysinfo("mailreceive")
				objmail.htmlbody=t2
				objmail.send 
				set objmail=nothing
				set objconfig=nothing
				if err then 
					response.Write "组件：cdosys，函数：sendmail<br>详情："&err.description,0
					err.clear
					exit function
				else
					sendmail=true
				end if
		
	end function
	
	
public function usermail(byval t1,byval t2,byval t3)

	on error resume next
		dim objmail,objconfig
				set objmail=server.createobject("cdo.message") 
				set objconfig=server.createobject("cdo.configuration") 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")="true" 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")=jianbook.sysinfo("smtp")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendusername")=jianbook.sysinfo("mailuser")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")=jianbook.sysinfo("mailpass")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/languagecode")="0x0804" 
				objconfig.fields.update() 
				set objmail.configuration=objconfig
				objmail.subject=t1
				objmail.from=jianbook.sysinfo("mailuser")
				objmail.to=t3
				objmail.htmlbody=t2
				objmail.send 
				set objmail=nothing
				set objconfig=nothing
				if err then 
					response.Write "组件：cdosys，函数：sendmail<br>详情："&err.description,0
					err.clear
					exit function
				
				end if
		
	end function	
	
	
public function regemail(byval t1,byval t2,byval t3)

	on error resume next
		dim objmail,objconfig
				set objmail=server.createobject("cdo.message") 
				set objconfig=server.createobject("cdo.configuration") 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")="true" 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")=jianbook.sysinfo("smtp")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendusername")=jianbook.sysinfo("mailuser")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")=jianbook.sysinfo("mailpass")
				objconfig.fields("http://schemas.microsoft.com/cdo/configuration/languagecode")="0x0804" 
				objconfig.fields.update() 
				set objmail.configuration=objconfig
				objmail.subject=t1
				objmail.from=jianbook.sysinfo("mailuser")
				objmail.to=t3
				objmail.htmlbody=t2
				objmail.send 
				set objmail=nothing
				set objconfig=nothing
				if err then 
					response.Write "{""info"": ""邮件组件错误："&JSONEncode(err.description)&""",""status"":""n""}"
					err.clear
					exit function
				else
				response.write "{""info"": ""发送邮件成功"",""status"": ""y""}"
				end if
		
	end function	
	
	
 Function JSONEncode(ByVal val)
		val = Replace(val, "\", "\\")
		val = Replace(val, """", "\""")
		'val = Replace(val, "/", "\/")
		val = Replace(val, Chr(8), "\b")
		val = Replace(val, Chr(12), "\f")
		val = Replace(val, Chr(10), "\n")
		val = Replace(val, Chr(13), "\r")
		val = Replace(val, Chr(9), "\t")
		JSONEncode = Trim(val)
End Function
	
Function un_asc(UnicodeStr)
 If InStr(UnicodeStr,"&#")>0 Then
  Dim Str,AsciiStr
  
  Str=Split(UnicodeStr,"&#")
  
  AsciiStr=""
  
  For i=0 To UBound(Str)
   If Str(i)<>"" Then
    AsciiStr=AsciiStr&ChrW(Left(Str(i),Len(Str(i))-1))
   End If
  Next
  
  un_asc=AsciiStr
 Else
  un_asc=UnicodeStr
 End If
End Function
 Function nohtml(str)
 Dim re
 Set re=new RegExp
 re.IgnoreCase = True
 re.Global = True
 re.Pattern="(\<.*?\>)"
 str=re.replace(str,"")
 re.Pattern="(\<\/.*?\>)"
 str=re.replace(str,"")
 nohtml=str
End Function 

public function keyfilter(t1)
key=sysinfo("filter_key")
if isnull(key) or key="" then keyfilter=t1:exit function
keyarr=split(key,"|")

for each it in keyarr
keystr=""
for ki=0 to len(it)
keystr=keystr&"*"
next
t1=replace(t1,it,keystr)
next
keyfilter=t1
end function

	public function enhtml(byval t0)
	set reg=new regexp
		if isnull(t0) then enhtml="":exit function
		if t0="<p>&nbsp;</p>" then enhtml="":exit function
		
		
		reg.pattern ="<script.+?/script>"
		t0=reg.replace(t0,"")
		reg.pattern ="<iframe.+?/iframe>"
		t0=reg.replace(t0,"")
		t0=replace(t0,"&","&amp;")
		t0=replace(t0,"'","&#39;")
		t0=replace(t0,"""","&#34;")
		t0=replace(t0,"<","&lt;")
		t0=replace(t0,">","&gt;")
		reg.pattern="(w)(here)"
		t0=reg.replace(t0,"$1h&#101;re")
		reg.pattern="(s)(elect)"
		t0=reg.replace(t0,"$1el&#101;ct")
		reg.pattern="(i)(nsert)"
		t0=reg.replace(t0,"$1ns&#101;rt")
		reg.pattern="(c)(reate)"
		t0=reg.replace(t0,"$1r&#101;ate")
		reg.pattern="(d)(rop)"
		t0=reg.replace(t0,"$1ro&#112;")
		
		reg.pattern="(d)(elete)"
		t0=reg.replace(t0,"$1el&#101;te")
		reg.pattern="(u)(pdate)"
		t0=reg.replace(t0,"$1p&#100;ate")
		reg.pattern="(\s)(or)"
		t0=reg.replace(t0,"$1o&#114;")
		reg.pattern="(java)(script)"
		t0=reg.replace(t0,"$1scri&#112;t")
		reg.pattern="(j)(script)"
		t0=reg.replace(t0,"$1scri&#112;t")
		reg.pattern="(vb)(script)"
		t0=reg.replace(t0,"$1scri&#112;t")
		if instr(t0,"expression")<>0 then
			t0=replace(t0,"expression","e&#173;xpression",1,-1,0)
		end if
		t0 = replace(t0,"{link http","<a target=_blank href=http")
        t0 = replace(t0, "{/link}","</a>")
		t0 = replace(t0,"{img http","<img src=http")
        t0 = replace(t0, "{h1}","<h1>")
		 t0 = replace(t0, "{/h1}","</h1>")
		 t0 = replace(t0, "{b}","<b>")
		 t0 = replace(t0, "{/b}","</b>")
		  t0 = replace(t0, "{color gray}","<font color=#999>")
		  t0 = replace(t0, "{color black}","<font color=#000>")
		 t0 = replace(t0, "{color red}","<font color=#FF5722>")
		 t0 = replace(t0, "{color green}","<font color=#009688>")
		 t0 = replace(t0, "{color blue}","<font color=#01AAED>")
		 t0 = replace(t0, "{/color}","</font>")
		 t0 = replace(t0, "}",">")
		t0 = replace(t0,chr(13)&chr(10),"<br>")
		enhtml=t0
	end function	
	
	
	public function clearhtml(byval t0)
	set reg=new regexp
		if isnull(t0) then clearhtml="":exit function
		if t0="<p>&nbsp;</p>" then clearhtml="":exit function
		
		reg.pattern ="<script.+?/script>"
		t0=reg.replace(t0,"")
		reg.pattern ="<iframe.+?/iframe>"
		t0=reg.replace(t0,"")
		t0=replace(t0,"&","&amp;")
		t0=replace(t0,"'","&#39;")
		t0=replace(t0,"""","&#34;")
		t0=replace(t0,"<","&lt;")
		t0=replace(t0,">","&gt;")
		reg.pattern="(w)(here)"
		t0=reg.replace(t0,"$1h&#101;re")
		reg.pattern="(s)(elect)"
		t0=reg.replace(t0,"$1el&#101;ct")
		reg.pattern="(i)(nsert)"
		t0=reg.replace(t0,"$1ns&#101;rt")
		reg.pattern="(c)(reate)"
		t0=reg.replace(t0,"$1r&#101;ate")
		reg.pattern="(d)(rop)"
		t0=reg.replace(t0,"$1ro&#112;")
		
		reg.pattern="(d)(elete)"
		t0=reg.replace(t0,"$1el&#101;te")
		reg.pattern="(u)(pdate)"
		t0=reg.replace(t0,"$1p&#100;ate")
		reg.pattern="(\s)(or)"
		t0=reg.replace(t0,"$1o&#114;")
		reg.pattern="(java)(script)"
		t0=reg.replace(t0,"$1scri&#112;t")
		reg.pattern="(j)(script)"
		t0=reg.replace(t0,"$1scri&#112;t")
		reg.pattern="(vb)(script)"
		t0=reg.replace(t0,"$1scri&#112;t")
		t0=reg.replace(t0,"$1o&#114;")
		if instr(t0,"expression")<>0 then
			t0=replace(t0,"expression","e&#173;xpression",1,-1,0)
		end if
		t0=keyfilter(t0)
		clearhtml=t0
	end function	
	

Function formatdate(Byval sTheDate)
' 格式化显示时间为几个月,几天前,几小时前,几分钟前,或几秒前
    Dim iSeconds, iMinutes, iHours, iDays

    iSeconds = DateDiff("s", sTheDate, Now())  'd/h/n/s
    iMinutes = Int(iSeconds/60)
    iHours = Int(iSeconds/3600)
    iDays = Int(iSeconds/86400)

    If iDays > 60 Then
        formatdate = formatdatetime(sTheDate,2)
    ElseIf iDays > 30 Then
        formatdate = "1个月前"
    ElseIf iDays > 14 Then
        formatdate = "2周前"
    ElseIf iDays > 7 Then
        formatdate = "1周前"
    ElseIf iDays > 1 Then
        formatdate = iDays & "天前"
    ElseIf iHours > 1 Then
        formatdate = iHours & "小时前"
    ElseIf iMinutes > 1 Then
        formatdate = iMinutes & "分钟前"
    ElseIf iSeconds >= 1 Then
        formatdate = iSeconds & "秒前"
    Else
        formatdate = "1秒前"
    End If
End Function

	
public function checkstr(byval t0,byval t1)
		dim t2
		select case t1
			case "null":checkstr=isnull(t0):exit function
			case "en":t2="^[a-zA-Z]+$"
			case "cn":t2="^[\u4e00-\u9fa5]+$"
			case "int":t2="^[-\+]?\d+$"
			case "price":t2="^\d+(\.\d+)?$"
			case "username":t2="^[a-zA-Z0-9_]{5,20}$"
			case "password":t2="^[a-zA-Z0-9.]{6,16}$"
			case "email":t2="^[\w\-\.]+@[a-zA-Z0-9]+\.(([a-zA-Z0-9]{2,4})|([a-zA-Z0-9]{2,4}\.[a-zA-Z]{2,4}))$"
			case "date":checkstr=isdate(t0):exit function
			case "qqemail":t2="^[\w\-\.]+@qq.com"
			case "tel":t2="^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$"
			case "mobile":t2="^(\+?\d{2,3})?0?1(3\d|5\d|7[0]|8[0256789])\d{8}$"
			case "zipcode":t2="^\d{6}$"
			case "qq":t2="^[1-9]\d{4,15}$"
			case "url":t2 = "^(http|https|ftp):\/\/[a-zA-Z0-9]+\.[a-zA-Z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\""])*$"
			case "ip":t2="^((25[0-5]|2[0-4]\d|(1\d|[1-9])?\d)\.){3}(25[0-5]|2[0-4]\d|(1\d|[1-9])?\d)$"
			case "file":t2="^[a-zA-Z0-9/_-]{1,50}$"
			case "filename":t2="^[a-zA-Z0-9._/]{1,50}$"
			case "urlname":t2="^[a-zA-Z0-9]{1,50}$"
		end select
		set reg=new regexp
		reg.pattern=t2
		checkstr=reg.test(trim(t0))
	end function

end class
%>
